//
//  BK_my_evaluationCommon.m
//  bestkeep
//
//  Created by 李明 on 2016/12/12.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BK_my_evaluationCommon.h"
#import "RequestManager.h"

NSString * const formalEnvironmentEvaluationStrBKAPI = @"http://api.bestkeep.cn/";

NSString *const BK_my_evaluationAPI = @"http://api.test.bestkeep.cn/";
NSString *const BK_my_evaluationAddEvalute = @"evaluation/addEvaluation";
NSString *const BK_my_evaluationAddEvaluteImg = @"evaluation/uploadImg";

@implementation BK_my_evaluationCommon


+ (NSString *)formalEnvironment:(NSString *)url {
    if (ApplicationEnvironmentProduction == 1) {
        return [formalEnvironmentEvaluationStrBKAPI stringByAppendingString:url];
    }
    return [BK_my_evaluationAPI stringByAppendingString:url];
}



/**
 上传图片

 @param data 图片Data
 @param callBack 返回数据
 */
+ (void)uploadEvaluationImgToServiceForData:(NSData *)data callback:(BK_my_evaluationCallBack)callBack {
    NSString *url = [self formalEnvironment:BK_my_evaluationAddEvaluteImg];
    BKFileObject *file = [[BKFileObject alloc] init];
    file.name = @"picture";
    file.fileName = @"image.jpg";
    file.data = data;
    [[RequestManager manager] bkUploadRequest:RequestMethodPost URLString:url parameters:nil file:file success:^(id  _Nullable responseObject) {
        if (responseObject) {
            NSDictionary * dataDict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
            callBack(dataDict, nil); 
        }
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        callBack(nil, error);
    }];
}



/**
 上传文字和图片

 @param dict 上传数据的字典
 @param callback 返回值
 */
+ (void)uploadEvaluationToServiceForDict:(NSDictionary *)dict callBack:(BK_my_evaluationCallBack)callback {
    NSString *url = [self formalEnvironment:BK_my_evaluationAddEvalute];
    [[RequestManager manager] bkDataRequest:RequestMethodPost URLString:url parameters:dict success:^(id  _Nullable responseObject) {
        callback(responseObject, nil);
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        callback(nil, error);
    }];
}

@end
